package com.itheima.d4_byte__stream;

import javax.xml.stream.XMLInputFactory;
import java.io.*;

public class FileInputStreamTest1 {
    public static void main(String[] args) throws IOException {
        //创建文件字节输入流管道
        InputStream fileInputStream = new FileInputStream("D:\\Java\\JavaEE_learn\\IO_learn\\src\\main\\java\\com\\itheima\\itheima01.txt");

        //public abstract int read() ；每次读取一个字节返回，如果没有数据了，返回-1
        int read = fileInputStream.read();
        System.out.println((char)read);

        int b2 = fileInputStream.read();
        System.out.println((char) b2);

        int b3 = fileInputStream.read();
        System.out.println((char) b3);

        //3.使用循环改造上述代码
        int b;//用于记住读取的字节
        while ((b = fileInputStream.read()) != -1){
            System.out.print((char) b);
        }

        //读取数据的性能很差
        //读取的汉字会乱码
        //流使用完毕之后，必须关闭，释放资源
        fileInputStream.close();
    }
}
